package net.lcheng.manage.controller;

import net.lcheng.commons.utils.PageList;
import net.lcheng.manage.utils.ControllerUtils;
import net.lcheng.model.User;
import net.lcheng.service.SysPermissionsService;
import net.lcheng.service.UserService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import java.sql.Date;

/**
 * Created by zwr on 2016/7/7 0007.
 */
@Controller
public class UserController {
    @Autowired
    private UserService userService;
    @Autowired
    private SysPermissionsService permissionsService;
    private final int PAGESIZE = 10;
    @RequiresPermissions("user:management")
    @RequestMapping(value = "user_management", method = RequestMethod.GET)
    public String UserMangementGet(Model model, @RequestParam(defaultValue = "1", required = false) int page, HttpServletRequest request) {
        ControllerUtils.common(model,  permissionsService,"user:management" );
        String userName = request.getParameter("userName");
        String stime = request.getParameter("stime");
        String etime = request.getParameter("etime");
        Date sdate = null;
        Date edate = null;
        try {
            sdate = Date.valueOf(stime);
            edate = Date.valueOf(etime);
        } catch (Exception ex) {
        }
        /**商品查询*/
        PageList<User> userPageList = userService.setUserList(page, PAGESIZE, userName, sdate, edate);
        model.addAttribute("userName", userName);
        model.addAttribute("stime", stime);
        model.addAttribute("etime", etime);
        model.addAttribute("list", userPageList.list);
        model.addAttribute("pageIndex", page);
        model.addAttribute("totalPage", userPageList.totalPage);

        return "user_management";
    }


}
